Merge the iwtransclusion branch back into trunk
[lhc/web/wiklou.git] / includes / Title.php
index 4f61897..f209995 100644 (file)
@@ -757,6 +757,20 @@ class Title {
                return $this->mPrefixedText;
        }
 
+       /**
+        * Return the prefixed title with spaces _without_ the interwiki prefix
+        * 
+        * @return \type{\string} the title, prefixed by the namespace but not by the interwiki prefix, with spaces
+        */
+       public function getSemiPrefixedText() {
+               if ( !isset( $this->mSemiPrefixedText ) ){
+                       $s = ( $this->mNamespace === NS_MAIN ? '' : $this->getNsText() . ':' ) . $this->mTextform;
+                       $s = str_replace( '_', ' ', $s );
+                       $this->mSemiPrefixedText = $s;
+               }
+               return $this->mSemiPrefixedText; 
+       }
+
        /**
         * Get the prefixed title with spaces, plus any fragment
         * (part beginning with '#')
@@ -1009,8 +1023,12 @@ class Title {
         * @return String the URL
         */
        public function getInternalURL( $query = '', $variant = false ) {
-               global $wgInternalServer, $wgServer;
-               $server = $wgInternalServer !== false ? $wgInternalServer : $wgServer;
+               if ( $this->isExternal( ) ) {
+                       $server = '';
+               } else {
+                       global $wgInternalServer, $wgServer;
+                       $server = $wgInternalServer !== false ? $wgInternalServer : $wgServer;
+               }
                $url = wfExpandUrl( $server . $this->getLocalURL( $query, $variant ), PROTO_HTTP );
                wfRunHooks( 'GetInternalURL', array( &$this, &$url, $query ) );
                return $url;
@@ -2836,6 +2854,10 @@ class Title {
                $this->mFragment = str_replace( '_', ' ', substr( $fragment, 1 ) );
        }
 
+       public function setInterwiki( $interwiki ) {
+               $this->mInterwiki = $interwiki;
+       }
+
        /**
         * Get a Title object associated with the talk page of this article
         *
@@ -3140,6 +3162,8 @@ class Title {
         * @return Mixed true on success, getUserPermissionsErrors()-like array on failure
         */
        public function moveTo( &$nt, $auth = true, $reason = '', $createRedirect = true ) {
+               global $wgContLang, $wgEnableInterwikiTemplatesTracking, $wgGlobalDatabase;
+
                $err = $this->isValidMoveOperation( $nt, $auth, $reason );
                if ( is_array( $err ) ) {
                        return $err;
@@ -3196,6 +3220,15 @@ class Title {
                        );
                }
 
+               if ( $wgEnableInterwikiTemplatesTracking && $wgGlobalDatabase ) {
+                       $dbw2 = wfGetDB( DB_MASTER, array(), $wgGlobalDatabase );
+                       $dbw2->update( 'globaltemplatelinks',
+                                               array(  'gtl_from_namespace' => $nt->getNamespace(),
+                                                               'gtl_from_title' => $nt->getText() ),
+                                               array ( 'gtl_from_page' => $pageid ),
+                                               __METHOD__ );
+               }
+
                if ( $protected ) {
                        # Protect the redirect title as the title used to be...
                        $dbw->insertSelect( 'page_restrictions', 'page_restrictions',
@@ -3289,8 +3322,8 @@ class Title {
         * @param $createRedirect Bool Whether to leave a redirect at the old title.  Ignored
         *   if the user doesn't have the suppressredirect right
         */
-       private function moveToInternal( &$nt, $reason = '', $createRedirect = true ) {
-               global $wgUser, $wgContLang;
+       private function moveOverExistingRedirect( &$nt, $reason = '', $createRedirect = true ) {
+               global $wgUseSquid, $wgUser, $wgContLang, $wgEnableInterwikiTemplatesTracking, $wgGlobalDatabase;
 
                $moveOverRedirect = $nt->exists();
 
@@ -3340,6 +3373,14 @@ class Title {
                                array( 'rc_timestamp' => $rcts, 'rc_namespace' => $newns, 'rc_title' => $newdbk, 'rc_new' => 1 ),
                                __METHOD__
                        );
+                       
+                        if ( $wgEnableInterwikiTemplatesTracking && $wgGlobalDatabase ) {
+                               $dbw2 = wfGetDB( DB_MASTER, array(), $wgGlobalDatabase );
+                               $dbw2->delete( 'globaltemplatelinks',
+                                                       array(  'gtl_from_wiki' => wfGetID(),
+                                                                       'gtl_from_page' => $newid ),
+                                                       __METHOD__ );
+               }
                }
 
                # Save a null revision in the page's history notifying of the move